home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Testing & Debugging / Debuggers & dcmds / MacsBug 6.5d9 / dcmds / C Samples / Vbl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  3.2 KB  |  162 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        VBL.c
  3.  
  4.     Contains:    This is the VBL dcmd.
  5.  
  6.     Written by:    xxx put writers here xxx
  7.  
  8.     Copyright:    © 1988,1993 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      9/9/93    DAL        now displays all nonempty SlotVBL queues as well as the regular
  13.                                     VBL queue; cleaned up the output
  14.  
  15.     Modification history:
  16.          2Dec88 sad        written from VCB.
  17.  
  18.     The following MPW commands will build the dcmd and copy it to the
  19.     "Debugger Prefs" file in the System folder. The dcmd's name in
  20.     MacsBug will be the name of the file built by the Linker.
  21.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  22.     C Samples folder into this folder.
  23.  
  24.     C Put.c
  25.     C VBL.c
  26.     Link dcmdGlue.a.o VBL.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o VBL
  27.     BuildDcmd VBL 1001
  28.     Echo 'include "VBL";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  29. */
  30.  
  31. /*
  32.     TO DO
  33.     -----
  34.     identify the task's owner in some way
  35. */
  36.  
  37. #include <Types.h>
  38. #include <OSUtils.h>
  39. #include <Retrace.h>
  40.  
  41. #include "dcmd.h"
  42. #include "put.h"
  43.  
  44. #define VBLQueue ((QHdrPtr)0x160)
  45.  
  46.  
  47. static void DrawVBL(VBLTask* vblp)
  48. {
  49.     PutUHexZTo((unsigned long)vblp,8,8);
  50.     PutSpacesTo(10);
  51.     PutUHexWord(vblp->vblCount);
  52.     PutSpacesTo(17);
  53.     PutUHexWord(vblp->vblPhase);
  54.     PutSpacesTo(24);
  55.     PutUHexZTo((unsigned long)vblp->vblAddr,8,27);
  56.     PutLine();
  57. }
  58.  
  59.  
  60. void DumpOneVBLQueue(QHdrPtr theQueue, short slotNum, dcmdBlock* paramPtr)
  61. {
  62.     VBLTask* vblp;
  63.     int numvbls = 0;
  64.  
  65.     PutLine();
  66.     PutPStr("\pVBL tasks");
  67.     if(slotNum != -1)
  68.       {
  69.         PutPStr("\p for slot ");
  70.         PutUDec(slotNum);
  71.       }
  72.  
  73.     if (theQueue->qFlags & 0x4000)
  74.         PutPStr("\p (queue executing)");
  75.     else
  76.         PutPStr("\p (queue not executing)");
  77.     PutLine();
  78.  
  79.     vblp = (VBLTask*)(theQueue->qHead);
  80.  
  81. //                             1         2         3         4         5         6         7
  82. //                    1234567890123456789012345678901234567890123456789012345678901234567890
  83.     dcmdDrawLine("\p VBLTask  Count  Phase  Code");
  84.     dcmdDrawLine("\p -------  -----  -----  ----");
  85.  
  86.     while (vblp)
  87.       {
  88.         DrawVBL(vblp);
  89.         numvbls++;
  90.         if (paramPtr->aborted) break;
  91.         if (vblp->qLink == 0)
  92.             if (vblp != (VBLTask*)(theQueue->qTail))
  93.                 dcmdDrawLine("\pVBL queue does not end at VBLQueue.qTail");
  94.         vblp = (VBLTask*)vblp->qLink;
  95.       }
  96.  
  97.     PutUDec(numvbls);
  98.     if(numvbls==1)
  99.         PutPStr("\p VBL task");
  100.     else
  101.         PutPStr("\p VBL tasks");
  102.     PutLine();
  103. }
  104.  
  105.  
  106. short GetQueueSize(QHdrPtr theQueue)
  107. {
  108.     VBLTask* vblp;
  109.     int count = 0;
  110.  
  111.     vblp = (VBLTask*)(theQueue->qHead);
  112.  
  113.     while (vblp)
  114.       {
  115.         count++;
  116.         if(count>1000)
  117.             return count;    // avoid infinite loop if queue is hosed
  118.         vblp = (VBLTask*)vblp->qLink;
  119.       }
  120.  
  121.     return count;
  122. }
  123.  
  124.  
  125. pascal void CommandEntry(dcmdBlock* paramPtr)
  126. {
  127.     switch (paramPtr->request)
  128.     {
  129.         case dcmdInit:
  130.             break;
  131.  
  132.         case dcmdHelp:
  133.             dcmdDrawLine("\pvbl");
  134.             dcmdDrawLine("\p   Lists tasks in the regular and slot VBL queues.");
  135.             break;
  136.  
  137.         case dcmdDoIt:
  138.         {
  139.             short slotNum;
  140.             QHdrPtr *slotQueueArray = *(QHdrPtr **)0x0D04;
  141.             
  142.             dcmdSwapWorlds();
  143.  
  144.             DumpOneVBLQueue(VBLQueue,-1,paramPtr);
  145.             for(slotNum=0; slotNum<=14; slotNum++)
  146.               {
  147.                 if(GetQueueSize(slotQueueArray[slotNum]))
  148.                     DumpOneVBLQueue(slotQueueArray[slotNum], slotNum, paramPtr);
  149.               }
  150.  
  151.             dcmdSwapWorlds();
  152.         }
  153.             break;
  154.  
  155.         default:
  156.             PutPStr("\punknown request ");
  157.             PutUDec(paramPtr->request);
  158.             PutLine();
  159.             break;
  160.     }
  161. }
  162.